﻿using AutoMapper;
using B.S.Packaged.Domain;
using B.S.Packaged.ErrorCode;
using B.S.Packaged.WebAPI.Read.Application.Command.MonitorCommand;
using MediatR;
using SqlSugar;

namespace B.S.Packaged.WebAPI.Read.Application.CommandHander.MonitorCommandHander
{
    public class GetMonitorCommandHander : IRequestHandler<GetMonitorCommand, APIResult<List<MonitorModel>>>
    {
        private readonly IMapper mapper;
        private readonly ISqlSugarClient db;

        public GetMonitorCommandHander(IMapper mapper, ISqlSugarClient db)
        {
            this.mapper = mapper;
            this.db = db;
        }
        public async Task<APIResult<List<MonitorModel>>> Handle(GetMonitorCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<MonitorModel>> result = new APIResult<List<MonitorModel>>();

            var list = await db.Queryable<MonitorModel>().ToListAsync();
            result.data = list;
            if (result.data != null)
            {
                result.code = APIResultCode.success;
                result.msg = "查询过程监控信息成功";
            }
            else
            {
                result.code = APIResultCode.failed;
                result.msg = "查询过程监控信息失败";
            }

            return result;
        }
    }
}
